    <template>
        <div>



    <h1>康复信息列表</h1>

<input type="text" placeholder="名称模糊" v-model="getdataquery.name">
<input type="button" value="查询" @click="querydata">


<a href="/add">新增康复信息</a>
<table class="table">

    <thead>
        <tr>
            <td>
                <input type="checkbox" @change="selectid" v-model="ischeck">
            </td>
            <td>id</td>
            <td>code</td>
            <td>name</td>
            <td>isDeleted</td>
            <td>start</td>
            <td>sericesTime</td>
            <td>操作</td>
        </tr>
    </thead>
    <tbody>
        <tr v-for="d in data">
            <td>
                <input v-model="idlist" type="checkbox" :value="d.id">
            </td>
            <td>{{d.id}}</td>
            <td>{{d.code}}</td>
            <td>{{d.name}}</td>
            <td>{{d.isDeleted}}</td>
            <td>{{d.start?"启用":"禁用"}}</td>
            <td>{{d.sericesTime}}</td>
            <td>操作</td>
        </tr>
    </tbody>
</table>

<input type="button" value="首页" @click="page(1)">
<input type="button" value="上一页" @click="page(2)">
<input type="button" value="下一页" @click="page(3)">
<input type="button" value="尾页" @click="page(4)">

一共{{pagedata.count}}条，一共{{pagedata.pcount}}页，每页显示{{getdataquery.size}}条，当前第{{getdataquery.index}}页，

<select v-model="getdataquery.size" @change="setsize">
    <option>2</option>
    <option>3</option>
    <option>5</option>
</select>
<input type="text" v-model="getdataquery.index">
<input type="button" value="跳转" @click="setindex">
<input type="button" value="批量启用/禁用" @click="updateloice">
        </div>
    </template>
    
    <script setup lang="ts">
    import axios from 'axios';
import { ref,onMounted } from 'vue';

//保存全选全取消的状态
const ischeck=ref(false)
//全选 全取消
const selectid=()=>{
    if(ischeck.value){

        data.value.forEach(e=>{
            idlist.value.push(e.id)
        })
    }
    else{
        idlist.value=[]
    }
 }

//保存选中行的多个编号
const idlist = ref([0])

//批量启用/禁用
const updateloice=()=>{

    if(!confirm("真的要修改吗")){
        return;
    }

    axios.get("https://localhost:7043/api/Rehabilitation/UpdateStart",{params:{idstring:idlist.value.toString()}}).then(res=>{
        if(res.data>0){
            alert('状态修改成功')
            getdata();
        }
        else{
            alert('状态修失败了。。。。')
        }
    })
}


    const data=ref([{
      "id": 0,
      "code": "",
      "name": "",
      "isDeleted": true,
      "start": true,
      "sericesTime": 0
    }])

// 条件查
const querydata=()=>{
    getdataquery.value.index = 1 
    getdata();
}


//跳转页面
const setindex=()=>{
    if(getdataquery.value.index>1 &&   getdataquery.value.index <= pagedata.value.pcount)
    {
        getdata()
    }
    else
    {
        getdataquery.value.index=1;
        getdata()
    }
}

//修改页容量
const setsize=()=>{
    getdataquery.value.index=1;
    getdata()
}

//翻页
    const page=(val:any)=>{
        if(val==1){
            getdataquery.value.index = 1;
            getdata()
        }
        if(val==2){

            if(getdataquery.value.index > 1)
            {
            getdataquery.value.index -=1;
            getdata()   
            }
        }
        if(val==3){

            if(getdataquery.value.index < pagedata.value.pcount)
            {
            getdataquery.value.index +=1;
            getdata()   
            }
        }
        if(val==4){
            getdataquery.value.index = pagedata.value.pcount;
            getdata()
        }
    }

        



    onMounted(()=>{
        getdata()
    })

    const pagedata=ref({
        count:0, //总记录数量 
        pcount:0 //总页数
    })
    const getdataquery=ref({
        index:1, //页码
        size:2, //页容量
        name:''  //条件 名称
    })

    const getdata=()=>{

        axios.get("https://localhost:7043/api/Rehabilitation/GetRehabilitationPageWhere",{params:getdataquery.value}).then(res=>{
            data.value = res.data.data;

            pagedata.value.count = res.data.count;
            pagedata.value.pcount  =  Math.ceil(    pagedata.value.count  /  getdataquery.value.size  )

            /* alert(pagedata.value.count )
            alert( pagedata.value.pcount) */

        })
    }


    </script>
    
    <style scoped>
    
    </style>